package com.jiazixuan.stock.controller;

import com.jiazixuan.stock.pojo.domain.SysPermissionDomain;
import com.jiazixuan.stock.pojo.entity.SysPermission;
import com.jiazixuan.stock.service.PermissionService;
import com.jiazixuan.stock.vo.req.PermissionAddVo;
import com.jiazixuan.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;
    /**
     * 查询所有权限集合
     */
    //TODO：有问题
    @GetMapping("/permissions")
    public R<List<SysPermission>> getAllPermissions(){
        return permissionService.getAllPermissions();
    }

    /**
     *  添加权限时回显权限树，仅仅显示目录和菜单
     */
    @GetMapping("/permissions/tree")
    public R<List<SysPermissionDomain>> getPermissionsTree(){
        return permissionService.getPermissionsTree();
    }

    /**
     * 权限添加按钮
     */
    @PostMapping("/permission")
    public R addPer(@RequestBody PermissionAddVo vo){
        return permissionService.addPer(vo);
    }

    /**
     * 更新权限
     */
    @PutMapping("/permission")
    public R updatePer(@RequestBody PermissionAddVo vo){
        return permissionService.updatePer(vo);
    }

    /**
     * 删除权限
     */
    @DeleteMapping("/permission/{permissionId}")
    public R deletePer(@PathVariable (value = "permissionId") String permissionId){
        return permissionService.deletePer(permissionId);
    }
}
